Skip to content

Conversation

@HosseinYousefi
Copy link
Member

@HosseinYousefi HosseinYousefi commented Aug 12, 2025

Uses a map on the Java side to store all the plugin instances with the key of engineId. On the Dart side, we use the engineId to access to correct Flutter Engine's context even when there are multiple. Same goes for the activity. Since activity is a more volatile thing, documentation has been added to warn users about the limitations of this.

There really isn't a great way to test this via integration tests (having multiple flutter engines).

@github-actions
Copy link

github-actions bot commented Aug 12, 2025

PR Health

Breaking changes ✔️
Package Change Current Version New Version Needed Version Looking good?
jni Breaking 0.14.2 0.15.0-wip 0.15.0 ✔️

This check can be disabled by tagging the PR with skip-breaking-check.

Changelog Entry ✔️
Package Changed Files

Changes to files need to be accounted for in their respective changelogs.

This check can be disabled by tagging the PR with skip-changelog-check.

API leaks ✔️

The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.

Package Leaked API symbol Leaking sources

This check can be disabled by tagging the PR with skip-leaking-check.

License Headers ✔️
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
Files
no missing headers

All source files should start with a license header.

Unrelated files missing license headers
Files
pkgs/objective_c/lib/src/ns_input_stream.dart

This check can be disabled by tagging the PR with skip-license-check.

@coveralls
Copy link

coveralls commented Oct 17, 2025

Coverage Status

coverage: 87.274% (-4.7%) from 91.972%
when pulling 5ff04fb on fix-context
into f7c7d52 on main.

@HosseinYousefi HosseinYousefi marked this pull request as ready for review November 5, 2025 19:26
/// activity.release();
/// }
/// }
/// ```
Copy link
Contributor

@liamappelbe liamappelbe Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These rules are similar to the rules for autorelease pools. I wonder if a similar API would work here, to make this less of a footgun:

static void withAndroidActivity(int engineId, void Function(JObject?) callback) {
  final activity = JniPlugin.getActivity(engineId);
  callback(activity);
  activity?.release();
}

Though this would look a bit weird, and I'm not sure if the marginal safety improvement is worth it. It's still possible to pass an async callback and use the activity after it's freed. You'd probably need some way of checking that the runtime type of the callback returns void to be fully safe (hack: assert(callback.runtimeType.endsWith(' void')) can distinguish "() => void" from "() => Future<void>"). This was less of a problem for the autorelease pools case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I thought that's hacky and you can still do some Isolate.run in the middle of it.

@HosseinYousefi HosseinYousefi merged commit f75c068 into main Nov 6, 2025
30 checks passed
@HosseinYousefi HosseinYousefi deleted the fix-context branch November 6, 2025 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package:jni package:jnigen type-infra A repository infrastructure change or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants